package org.example.controller.iim;

import jakarta.annotation.Resource;
import org.example.domain.Result;
import org.example.domain.iim.Elements;
import org.example.mapper.ElementsMapper;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @Author: whopxx
 * @CreateTime: 2025-01-06
 */
@RestController
@RequestMapping("/elements")
public class ElementsController {
    @Resource
    private ElementsMapper elementsMapper;

    // pid: 项目id
    @GetMapping("/list")
    public Result list(@RequestParam Integer pid) {
        List<Elements> interfaces = elementsMapper.selectByPid(pid);
        return Result.success(interfaces);
    }

    @PostMapping
    public Result add(@RequestBody Elements elements, @RequestParam Integer pid) {
        elements.setProjectId(pid);
        elementsMapper.insert(elements);
        return Result.success();
    }


    @PutMapping
    public Result update(@RequestBody Elements elements,@RequestParam Integer pid) {
        elements.setProjectId(pid);
        elementsMapper.updateById(elements);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam Integer id,@RequestParam Integer pid) {
        elementsMapper.deleteById(id);
        return Result.success();
    }
}
